package com.java.pertar.springlibary;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Component
@RestController
@RequestMapping("/book")
public class SpringBook {


    @Autowired
    BookInfo bookInfo;

    @RequestMapping("/getList")
    public List<BookInfo> bookList() {


        List<BookInfo> list = new ArrayList<>();
        for (int i = 0; i < 15; i++) {
            BookInfo bookInfo = new BookInfo();
            bookInfo.setId(i);
            bookInfo.setBookName("书名" + i);
            bookInfo.setAuthor("作者" + i);
            bookInfo.setCount(new Random().nextInt(100));
            bookInfo.setPrice(new BigDecimal(new Random().nextInt(100)));
            bookInfo.setPublish("出版社" + i);
            bookInfo.setStatus(i % 5 == 0 ? 2 : 1);
            list.add(bookInfo);

        }
        for (BookInfo bookInfo : list) {
            if (bookInfo.getStatus() == 1) {
                bookInfo.setStatusCN("可借阅");

            } else {
                bookInfo.setStatusCN("不可借阅");

            }
        }
        return list;
    }


}
